package com.hyb.controller;


import com.alibaba.fastjson.JSON;
import com.hyb.entity.Role;
import com.hyb.response.Result;
import com.hyb.service.RoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 *  角色Controller
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/loadmyrole",method = RequestMethod.GET)
    @ApiOperation("获取角色信息")
    public String loadRoles(String staffEmail){

        Set<String> roles = roleService.getRolesByStaffEmail(staffEmail);
        Map<String,Object> map = new HashMap<>();
        map.put("roles",roles);
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取成功").setData(roles));
    }


    @RequestMapping(value = "/loadAllRoleName",method = RequestMethod.GET)
    @ApiOperation("获取全部的角色")
    public String loadAllRolesName(){
        List<Role> roles = roleService.getAllRoles();
        Map<String,Object> map = new HashMap<>();
        map.put("AllRoles",roles);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(map));
    }
}
